Skip to main content

Overview

Phase 3 is the critical synthesis stage where all data from Phase 1 and Phase 2 is merged into a single unified JSON structure. This phase runs a single script that produces the base all_stocks_fundamental_analysis.json file.
If bulk_market_analyzer.py fails, the pipeline stops. Phase 4 scripts cannot proceed without the base JSON file.

Execution Order

Phase 3 runs one critical script:
1

Build Master JSON

Script: bulk_market_analyzer.pyMerges fundamental data, technical indicators, and listing dates into a unified structure.

Script: bulk_market_analyzer.py

Purpose

Merges data from multiple sources to create the base JSON with 86 fields per stock across 2,775 stocks.

Input Files

Data Merging Process

The script iterates through all stocks and merges data sections:

Output Files

Output Structure


Data Processing Steps

Step 1: Load All Data Sources

Step 2: Extract Quarterly Fundamentals

Step 3: Merge Technical Indicators

Step 4: Build Unified Record

Step 5: Save Output


Field Calculation Examples

Quarterly Changes (QoQ, YoY)

Pipe String Parsing

SMA/EMA Status Formatting


Dependencies

Required from Phase 1

  • fundamental_data.json (CRITICAL)
  • master_isin_map.json (for iteration)
  • dhan_data_response.json (for technical data)
  • nse_equity_list.csv (for listing dates)

Required from Phase 2

  • advanced_indicator_data.json (for SMA/EMA/Pivot)

Optional (Soft Dependencies)

  • If any file is missing, the script continues but fields will be empty/0

Typical Execution Time

~30-60 seconds — Pure in-memory data merging (no API calls)

Performance Breakdown

  • Load all JSONs: ~5s
  • Iterate 2,775 stocks: ~20s
  • Write output JSON: ~10s

Error Handling

Critical Failure Detection

Non-Critical Missing Files


Output Validation

File Size Check

Record Count Check

Field Completeness Check


What Phase 3 Does NOT Include

The base JSON does NOT include the following (populated in Phase 4):
These fields are placeholders (0 or empty arrays) in Phase 3:
  • Advanced Metrics: RVOL, ADR, ATH, Turnover, 200D EMA Volume
  • Earnings Performance: Returns since Earnings, Max Returns since Earnings
  • F&O Data: F&O Flag, Lot Size, Next Expiry
  • Event Markers: Surveillance, Insider Trading, Block Deals, Corporate Actions
  • Recent Announcements: Top 5 regulatory filings with PDF links
  • News Feed: Top 5 media news items with sentiment

Phase 3 Output Summary

Files Produced

Field Coverage

  • Complete: 60 fields (fundamentals, technicals, ratios, returns)
  • Placeholders: 26 fields (to be populated in Phase 4)

Next Phase

Once Phase 3 completes, the pipeline proceeds to:

Phase 4: Enrichment Injection

Modifies the master JSON in-place to inject advanced metrics, F&O data, earnings performance, and event markers. Order matters!